package cn.edu.yzu.scholarship.render;

import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;

import com.jfinal.render.Render;

public class JRExcelRender extends Render {
	private static final long serialVersionUID = 4804479700716995815L;
	
	private JasperReportBuilder builder = null;
	
	private String fileName;

	public JRExcelRender(JasperReportBuilder builder) {
		this.builder = builder;
	}


	@Override
	public void render() {
		try {
			response.setContentType("APPLICATION/OCTET-STREAM"); 
			response.setHeader("Content-Disposition", "attachment; filename="+ new String(fileName.getBytes("gb2312"),"ISO8859-1") +".xls"); 
			
			builder.toXls(response.getOutputStream());
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public JRExcelRender fileName(String fileName) {
		this.fileName = fileName;
		return this;
	}
}
